# -*- coding: utf-8 -*-
# @Date   : 2020/2/10
# @File   : PL01_CusAlertRiskIndex.py
# @Author : zhaochen
'''eof
name:客户预警风险指数
code:PL01_CusAlertRiskIndex
tableName:
columnName:
groups:PL模块
dependencies:DH_Warning
type:常用指标
datasourceType:在线指标
description:
eof'''


import sys
import json

reload(sys)
sys.setdefaultencoding('utf-8')

null_type_list = ['', ' ', None, 'null', 'Null', 'NULL', '/', '-', '--']

def isFloat(x):
    '''
    判断x为float类型且大于等于0
    '''
    try:
        if isinstance(float(x), float) and float(x) >= 0:
            if str(x) in ['inf', 'infinity', 'INF', 'INFINITY', 'True']:
                return False
            else:
                return True
        else:
            return False
    except:
        return False

def PL01_CusAlertRiskIndex():
    dh_warnings = DH_Warning
    if len(dh_warnings) == 0:
        return 0
    else:
        level1 = 0
        level2 = 0
        level3 = 0
        for warning in dh_warnings:
            warning_level = warning.get("warning_level")
            if warning_level == "I":
                level1 += 1
            elif warning_level == "II":
                level2 += 1
            elif warning_level == "III":
                level3 += 1
            else:
                pass
        return 5 * level1 + 4 * level2 + 3 * level3

result = PL01_CusAlertRiskIndex()
